<?php
namespace plugin\ky_black\app\admin\model;

use support\Model;

class CardBalanceLog extends Model
{
    /**
     * 关联到模型的数据表
     *
     * @var string
     */
    protected $table = 'ky_card_balance_log';

    /**
     * 主键
     *
     * @var string
     */
    protected $primaryKey = 'log_id';

    /**
     * 是否使用 updated_at
     *
     * @var bool
     */
    public $timestamps = false;

    /**
     * 可以批量赋值的属性
     *
     * @var array
     */
    protected $fillable = [
        'card_id',
        'card_no',
        'change_type',
        'amount',
        'before_balance',
        'after_balance',
        'before_available',
        'after_available',
        'before_frozen',
        'after_frozen',
        'related_id',
        'operator_id',
        'operator_name',
        'remark'
    ];

    /**
     * 类型转换
     *
     * @var array
     */
    protected $casts = [
        'amount' => 'decimal:2',
        'before_balance' => 'decimal:2',
        'after_balance' => 'decimal:2',
        'before_available' => 'decimal:2',
        'after_available' => 'decimal:2',
        'before_frozen' => 'decimal:2',
        'after_frozen' => 'decimal:2',
        'created_at' => 'datetime'
    ];

    /**
     * 关联黑卡
     */
    public function blackCard()
    {
        return $this->belongsTo(BlackCard::class, 'card_id', 'card_id');
    }

    /**
     * 关联操作人
     */
    public function operator()
    {
        return $this->belongsTo(Member::class, 'operator_id', 'user_id');
    }
} 